[HEADER]
	VERSION		01.00.00.00
	DESCRIPTION Anisotropic Lighting Example
	COPYRIGHT 	Imagination Technologies Ltd.
[/HEADER]

[TEXTURES] 
	// NO TEXTURES USED
[/TEXTURES]

[VERTEXSHADER] 
	NAME MyVertexShader 
		
	[GLSL_CODE]
		attribute vec3	myVertex;
		attribute vec3	myNormal;
		
		uniform mat4	myWVPMatrix;
		uniform mat3	myWorldViewIT;
		uniform vec3	myLightDirection;
		uniform vec3	myEyePos;
		
		varying float	diffuseIntensity;
		varying float	specularIntensity;
		
		const vec4 cMaterial = vec4(0.4,0.6,0.9,0.0);
		const vec3 cGrainDirection = vec3(1.0, 2.0, 0.0);

		void main(void)
		{
			gl_Position = myWVPMatrix * vec4(myVertex, 1.0);
			vec3 transNormal = normalize(myWorldViewIT * myNormal);
			
			vec3 normalXgrain = cross(transNormal, normalize(cGrainDirection));
			vec3 tangent = normalize(cross(normalXgrain, transNormal));
			float LdotT = dot(tangent, normalize(myLightDirection));
			float VdotT = dot(tangent, normalize(myEyePos));
			
			float temp = sqrt(1.0 - LdotT * LdotT);
			float NdotL = temp;
			float VdotR = temp * sqrt(1.0 - VdotT * VdotT) - VdotT * LdotT;
			
			diffuseIntensity = max(NdotL * cMaterial.x + cMaterial.y, 0.0);
			specularIntensity = max(VdotR * VdotR * cMaterial.z + cMaterial.w, 0.0);
		}
	[/GLSL_CODE]
[/VERTEXSHADER]
    
[FRAGMENTSHADER] 
	NAME MyFragShader 
		
	[GLSL_CODE]
		varying float	diffuseIntensity;
		varying float	specularIntensity;
		
		const vec3 cBaseColour = vec3(0.9, 0.2, 0.2);

		void main (void)
		{
			vec3 finalColour = (cBaseColour * diffuseIntensity) + specularIntensity;
			gl_FragColor = vec4(finalColour, 1.0);
		}
	[/GLSL_CODE]
[/FRAGMENTSHADER]
 
[EFFECT] 
	NAME AnisotropicEffect
		
	UNIFORM myWorldViewIT 		WORLDVIEWIT
	UNIFORM myWVPMatrix 		WORLDVIEWPROJECTION
	UNIFORM	myLightDirection	LIGHTDIRWORLD1
	UNIFORM	myEyePos			EYEPOSWORLD
	
	ATTRIBUTE myVertex 			POSITION 	
	ATTRIBUTE myNormal 			NORMAL 		
	
	VERTEXSHADER MyVertexShader
	FRAGMENTSHADER MyFragShader

[/EFFECT]
